import { defineStore } from 'pinia';
import { reactive } from 'vue';
import { reqCategory1List ,reqCategory2List,reqCategory3List} from '@/api/product/attr/index';
import type {cate} from '@/api/product/attr/model/index'

export interface tState {
    c1List: cate[];
    c1Id: number | string;
    c2List:cate[];
    c2Id:number|string;
    c3List: cate[];
    c3Id:number|string;
  }

const useCategoryStore = defineStore('category', () => {
  const state = reactive<tState>({
    c1List: [],
    c1Id: '',
    c2List:[],
    c2Id:'',
    c3List:[],
    c3Id:''
  });
  const reqCate1 = async () => {
    const res = await reqCategory1List();
    state.c1List = res;
  };
  const reqCate2 = async () => {
    state.c2Id = ''
    state.c3Id= ''
    state.c3List = []
    const res = await reqCategory2List(state.c1Id);
    state.c2List = res;
  };
  const reqCate3 = async () => {
    state.c3Id = ''
    const res = await reqCategory3List(state.c2Id);
    state.c3List = res;
  };
  return {
    reqCate1,
    reqCate2,
    reqCate3,
    state,
  };
});

export default useCategoryStore;
